package com.itcast.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itcast.dao.RoleDao;
import com.itcast.pojo.Role;
import com.itcast.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service(interfaceClass = RoleService.class)
@Transactional
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    public List<Role> findAll() {
        List<Role> all = roleDao.findAll();
        return all;
    }

    @Override
    public List<Integer> findRoleIdsByUserId(int userId) {
        Set<Role> roles = roleDao.findByUserId(userId);
        List<Integer> list = new ArrayList<>();
        for (Role role : roles) {
            list.add(role.getId());
        }
        return list;
    }
}
